/**
 * 提取进度条组件
 */
import React from 'react';
import { Progress, Card, Space, Typography } from 'antd';
import { LoadingOutlined, CheckCircleOutlined, CloseCircleOutlined } from '@ant-design/icons';

const { Text } = Typography;

interface ProgressBarProps {
  status: 'idle' | 'uploading' | 'extracting' | 'success' | 'error';
  current: number;
  total: number;
  message?: string;
}

const ProgressBar: React.FC<ProgressBarProps> = ({ status, current, total, message }) => {
  if (status === 'idle') {
    return null;
  }

  const percent = total > 0 ? Math.round((current / total) * 100) : 0;

  const getStatusConfig = () => {
    switch (status) {
      case 'uploading':
        return {
          icon: <LoadingOutlined />,
          color: '#1890ff',
          text: '正在上传文件...',
        };
      case 'extracting':
        return {
          icon: <LoadingOutlined />,
          color: '#1890ff',
          text: `正在提取字段... (${current}/${total})`,
        };
      case 'success':
        return {
          icon: <CheckCircleOutlined style={{ color: '#52c41a' }} />,
          color: '#52c41a',
          text: '提取完成！',
        };
      case 'error':
        return {
          icon: <CloseCircleOutlined style={{ color: '#ff4d4f' }} />,
          color: '#ff4d4f',
          text: '提取失败',
        };
      default:
        return {
          icon: null,
          color: '#1890ff',
          text: '',
        };
    }
  };

  const config = getStatusConfig();

  return (
    <Card style={{ marginBottom: 16 }}>
      <Space direction="vertical" style={{ width: '100%' }}>
        <Space>
          {config.icon}
          <Text strong>{config.text}</Text>
        </Space>
        <Progress
          percent={percent}
          status={status === 'error' ? 'exception' : status === 'success' ? 'success' : 'active'}
          strokeColor={config.color}
        />
        {message && (
          <Text type="secondary" style={{ fontSize: '12px' }}>
            {message}
          </Text>
        )}
      </Space>
    </Card>
  );
};

export default ProgressBar;

